import ifcopenshell

from src.database.connection import Neo4jInstance
from src.ifc.load.save import import_entities, import_relationships, flush_neo4j
from src.util.applog import AppLog

graph = Neo4jInstance.get_connect()


def load_ifc_to_neo4j(file_path):
    flush_neo4j()  # 清空数据
    ifc_file = ifcopenshell.open(file_path)
    node_dict = import_entities(ifc_file)
    AppLog.info("finish importing entities")
    import_relationships(ifc_file, node_dict, graph)
    AppLog.info("finish importing relationships")
